home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / 3dlib30b.zip / RTOBJ.H < prev    next >
C/C++ Source or Header  |  1994-03-10  |  5KB  |  138 lines

  1. /******************************************************************************
  2. *                                   rtobj.h                                   *
  3. *      please notice -                                                        *
  4. *      this unit includes both the object3d unit, and the superobj unit,      *
  5. *      and it is used with no reference to the WWToolKit window GUI library,  *
  6. *      uses project3, instead of prjWind  (It does, however, support OWL)     *
  7. *                                                                             *
  8. * In V2.x - The support collections are part of this unit as well ...         *
  9. * V3.x adds os/2 support                                                      *
  10. *                                                                             *
  11. *                                                                             *
  12. *                                 3D Objects                                   *
  13. *                                 ----------                                   *
  14. *                                                                              *
  15. *   A 3D object is a collection of points and lines in the 3D universe,        *
  16. *   that represent the body we want to draw on the screen.                     *
  17. *   A 3D object is allways centered around point (0, 0, 0) in the 3D universe. *
  18. *   (Its center of gravity assuming it is has a uniform weight distribution    *
  19. *    is in point (0, 0, 0)                                                     *
  20. *   At any moment during the object's life, we know it's distance from the     *
  21. *   origin, And it's rotation using reveres rotation CTM.                      *
  22. *                                                                              *
  23. *   3D Object methods:                                                         *
  24. *      constructor Open                                                        *
  25. *      destructor  CloseMe                                                     *
  26. *      procedures: Rotate, Scale, Move, Show, Hide, Load, Save                 *
  27. *                  SetToOrigin, Paint                                          *
  28. *                                                                              *
  29. ******************************************************************************/
  30.  
  31. #ifndef _rtobj_h
  32. #define _rtobj_h
  33.  
  34. #include <stdio.h>
  35. #include "ctm3d.h"
  36. #include "project3.h"
  37.  
  38. class baseObject {
  39.  
  40. public:
  41.  
  42.    ctmPtr myCtm;
  43.  
  44.    unsigned int myColor;
  45.    point3d location;
  46.    int scrPntUpdt; // TRUE if screen points updated.
  47.    char name[80];
  48.  
  49.    baseObject(char *myName, unsigned int color); // same as open in pascal
  50.    virtual ~baseObject();  // same as closeMe in pascal
  51.  
  52. #ifndef _windows
  53.    virtual void show();
  54.    virtual void hide();
  55.    virtual void paint();
  56. #endif
  57.  
  58.    virtual void updateScreenPoints();
  59.    virtual void move(axisType axis, double by);
  60.    virtual void translate(int dx,
  61.                           int dy,
  62.                           int dz);
  63.    virtual void scale(axisType axis, double factor);
  64.    virtual void allScale(double sx, double sy, double sz);
  65.    virtual void rotate(axisType axis, double deg);
  66.    virtual void goto3dPos(double x, double y, double z);
  67.    virtual void setToOrigin(); // translate to 0,0,0, update points and set ctm to unit.
  68.    virtual void calcLocation(); // set location to central gravity
  69.    virtual void deleteTransform(); // set myCtm to unit
  70.  
  71.    virtual unsigned int load(); // from disk 
  72.    virtual unsigned int save(); // to disk
  73.    virtual unsigned int writeMe(FILE *elementFile); // to disk, without opening file 
  74.    virtual unsigned int readMe(FILE *elementFile);
  75.  
  76.  
  77. }; // baseObject class definition
  78.  
  79. typedef baseObject *baseObjectPtr;
  80.  
  81. class obj3d : public baseObject {
  82.  
  83. public:
  84.  
  85.    point3d (*points)[];
  86.    line3d  (*lines)[];
  87.    screenPoints (*scrPoints)[];
  88.  
  89.    int numOfLines;
  90.    int numOfPoints;
  91.    ctmPtr reverseRot;
  92.    ctmPtr unReverseRot;
  93.  
  94.    obj3d(char *myName, point3d ref, unsigned int color);
  95.    virtual ~obj3d();
  96.  
  97.    virtual void paint();
  98.    virtual void updateScreenPoints(); 
  99.    virtual void calcLocation();
  100.    virtual void setToOrigin();
  101.    virtual unsigned int writeMe(FILE *elementFile);
  102.    virtual unsigned int readMe(FILE *elementFile);
  103.  
  104. }; // obj3d class definition
  105.  
  106. typedef obj3d *obj3dPtr;
  107.  
  108. class complexObj : public baseObject {
  109.  
  110. public: 
  111.    
  112.    obj3dPtr (*childs)[];
  113.    ctm   (*ctms)[];
  114.  
  115.    int numOfChilds;
  116.  
  117.    complexObj(char *myName, unsigned int color);
  118.    virtual ~complexObj();
  119.  
  120.    virtual void updateScreenPoints();
  121.    virtual unsigned int writeMe(FILE *elementFile);
  122.    virtual unsigned int readMe(FILE *elementFile);
  123.    virtual void calcLocation();
  124.    virtual void paint();
  125.    virtual void move(axisType axis, double by);
  126.    virtual void scale(axisType axis, double factor);
  127.    virtual void rotate(axisType axis, double deg);
  128.    unsigned int addSubObject(char *myName, point3d ref);
  129.    obj3dPtr getChildPtr(int index);
  130.    void rotateChild(int child, axisType axis, double deg);
  131.    void scaleChild(int child, axisType axis, double factor);
  132.    void moveChild(int child, axisType axis, double by);
  133.  
  134. }; // complexObj class definition
  135.  
  136.  
  137. #endif
  138.